package com.qianfeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.dto.Page;
import com.qianfeng.entity.Role;
import com.qianfeng.mapper.RoleMapper;
import com.qianfeng.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public void addRole(Role role) {
        roleMapper.addRole(role);
    }

    @Override
    public void deleteRole(Integer roleId) {
        roleMapper.deleteRole(roleId);
    }

    @Override
    public void updateRole(Role role) {
        roleMapper.updateRole(role);
    }

    @Override
    public List<Role> getRoleByRoleId(Integer roleId) {

        List<Role> role = roleMapper.getRoleByRoleId(roleId);
        return role;
    }

    @Override
    public List<Role> getRoleList() {
        List<Role> roleList = roleMapper.getRoleList();

        return roleList;
    }

    @Override
    public Page getRolePage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Role> roleList = roleMapper.getRoleList();
        Page page = new Page();
        PageInfo<Role> pageInfo = new PageInfo<>(roleList);
        page.setCount(pageInfo.getTotal());
        page.setObj(pageInfo.getList());
        page.setPages(pageInfo.getPages());
        return page;
    }
}
